using System;

namespace SeaVM.Instructions
{
    public class Instructions
    {
        public static void AssertAddress(VM vm,int address)
        {
            if(address < 0 || address >= vm.memory.size)
            {
                throw new VmRunError("地址越界:["+address+"]");
            }
        }

        public static void AssertDefine(VM vm,string define)
        {
            if(!vm.defines.ContainsKey(define))
            {
                throw new VmRunError("没有这个定义:["+define+"]");
            }
        }

        public static void AssertDataType(Data data,DataType type)
        {
            if(data.type != type)
            {
                throw new VmRunError(string.Format("需要{0}类型，此处为{1}类型",type,data.type));
            }
        }

        public static void AssertStackMinSize(VM vm,int size)
        {
            if(!(vm.stack.Count > size))
            {
                throw new VmRunError(string.Format("栈大小不足，当前数量为：{0},需求为>{1}",vm.stack.Count,size));
            }
        }
    }
}